<?php
  class Plugins_Reservationregister extends model {
  
  function getformadd($productid="")
  {




$code  = '<div class="wrpPlg clBg5 clBd2 bdFull">'."\n";
$code .= '<div class="wrpOutAtcPlg">'."\n";
$code .= '<div class="wrpAtcPlg">'."\n";
$code .= '<span class="ico3 icoRsvPlg"></span>'."\n";
$code .= '<div class="spnAtcPlg clTxtW">'."\n";
$code .= '<span class="txtAtcPlg fs03">Reservation</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpTl">'."\n";
$code .= '<div title="Close" class="btnIco closeTl clBd3 mgBtm10 deleterowbutton">'."\n";
$code .= '<span class="ico icoCloseTl"></span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '<form class="frmFrmPlg clTxt3 fs03">'."\n";
$code .= '<fieldset class="wrpFrmPlg">'."\n";
$code .= '<table class="tbGenInfo tbAddCtnt clTxt3 fs03">'."\n";
$code .= '<tbody><tr>'."\n";
$code .= '<th>User Type</th>'."\n";
$code .= '<td>'."\n";
$code .= '<div class="userRsv">'."\n";
$code .= '<input type="radio" class="checkdata1" checked="" value="0" id="genuser" name="premium[]">'."\n";
$code .= '<label for="genuser">All User Type</label>'."\n";
$code .= '<input type="radio" class="checkdata2" id="pmuser" value="1" name="premium[]">'."\n";
$code .= '<label for="pmuser">Member Plus</label>'."\n";
$code .= '</div>'."\n";
$code .= '</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Seat No.</th>'."\n";
$code .= '<td>'."\n";
$code .= '<input type="text" name="seat[]"  class="clBg5 clBd2 fs03 clTxt2" kl_virtual_keyboard_secure_input="on">'."\n";
$code .= '<div class="ulmSeat">'."\n";
$code .= '<input type="checkbox" name="unseat[]" value="1" id="ulms" class="ulmSeatCb">'."\n";
$code .= '<label for="ulms" class="ulmSeatLb">Unlimited Seat</label>'."\n";
$code .= '</div>'."\n";
$code .= '</td>'."\n";
$code .= '</tr>'."\n";
$code .= '<tr>'."\n";
$code .= '<th>Reserve No.</th>'."\n";
$code .= '<td>'."\n";
$code .= '<input type="text" name="reserve[]" class="clBg5 clBd2 fs03 clTxt2" kl_virtual_keyboard_secure_input="on">'."\n";
$code .= '<div class="ulmSeat">'."\n";
$code .= '<input type="checkbox" name="unreser[]" value="1" id="ulmr" class="ulmSeatCb">'."\n";
$code .= '<label for="ulmr" class="ulmSeatLb">Unlimited Reservation</label>'."\n";
$code .= '</div>'."\n";
$code .= '</td>'."\n";
$code .= '</tr>'."\n";

$code .= '<tr>'."\n";
$code .= '<th>List Name</th>'."\n";
$code .= '<td>'."\n";
$code .= '<div class="listName">'."\n";
$code .= '<input type="radio" checked="" class="checkdata3" value="1"  name="showlist[]">'."\n";
$code .= '<label for="shwln">Show</label>'."\n";
$code .= '<input type="radio"  value="0" class="checkdata4" name="showlist[]">'."\n";
$code .= '<label for="hdln">Hide</label>'."\n";
$code .= '</div>'."\n";
$code .= '</td>'."\n";
$code .= '</tr>';


$code .= '</tbody></table>'."\n";
$code .= '</fieldset>'."\n";
$code .= '</form>'."\n";
$code .= '</div>';

$arraydata['form']=addslashes(str_replace(array("\r", "", "\r"), '', $code));
return $arraydata;
  
  }
   function saveplugin($arraydata,$productid,$plugreid)
  {
  
  
  $arraydata['productid']=$productid;
  $arraydata['plugreid']=$plugreid;
   $this->db->db_set($arraydata,'tb_plugins_reservationregister');
  
  }

  
  
  
  function getuserlistreservation($productid,$status)
  {
  $page=1;
  if($_POST['page'])
  {
  $page=$_POST['page'];
  
  }
  $page=(($page - 1) * 10);
  $limit="limit  $page,10";
  $where='';
    if($_POST['search'])
  {
  $where=' and ( tb_user.username like "%'.$_POST['search'].'%" or tb_user.displayname like "%'.$_POST['search'].'%" ) ';
  
  }
  
  $sql="SELECT
            tb_plugins_reservationregister_value.`status`,
            tb_plugins_reservationregister_value.resvid,
            tb_plugins_reservationregister_value.userid,tb_user.imgmid,tb_user.simgmid,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,IF (tb_user.email = '', tb_user.emailfacebook,tb_user.email) as email,tb_user.phone,tb_user.username
            FROM
            tb_plugins_reservationregister_value
            inner join tb_user ON tb_user.userid=tb_plugins_reservationregister_value.userid 
             where tb_plugins_reservationregister_value.productid=".$productid.' and tb_plugins_reservationregister_value.`status`='.$status.' and tb_plugins_reservationregister_value.delete=0 '.$where.' '.$limit;
             

             
             
             
             
  $arrayuser=$this->db->db_set_recordset($sql);
  if(count($arrayuser))
  {
  $k=0;
  foreach($arrayuser as $valueuser)
  {
  
  
  
  $arrayuser[$k]['usersimg']= $this->getimagebyimgmid($valueuser['imgmid']);
  $arrayuser[$k]['userssimg']= $this->getimagebyimgmid($valueuser['simgmid']);
  
  
  
  $k++;
  
  }
  
  }
  return $arrayuser;
  
  
  }
  
  function countuserlistreservation($productid,$status)
  {
  $where='';
    if($_POST['search'])
  {
  $where=' and ( tb_user.username like "%'.$_POST['search'].'%" or tb_user.displayname like "%'.$_POST['search'].'%"  ) ';
  
  }
  
  $sql="
  SELECT count(*) as countdata FROM (
  SELECT
            tb_plugins_reservationregister_value.`status`,
            tb_plugins_reservationregister_value.resvid,
            tb_plugins_reservationregister_value.userid,tb_user.imgmid,tb_user.simgmid,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,IF (tb_user.email = '', tb_user.emailfacebook,tb_user.email) as email,tb_user.phone,tb_user.username
            FROM
            tb_plugins_reservationregister_value
            inner join tb_user ON tb_user.userid=tb_plugins_reservationregister_value.userid 
             where tb_plugins_reservationregister_value.productid=".$productid.' and tb_plugins_reservationregister_value.`status`='.$status.' and tb_plugins_reservationregister_value.delete=0 '.$where.' ) tb_d';
             


             
             
             
  $arrayuser=$this->db->db_set_1recordrow($sql);
  

  
  return $arrayuser;
  
  
  }
  
  function getformlanding($arraydata)
  {
  
  
$code  = '<div class="ldIt wrpFrmLd clBg4" id="reserveform-'.$arraydata['resid'].'">'."\n";

$code .= '<div class="wrpHdInfoGen mgBtm10">'."\n";
$code .= '<h2 class="clTxt2 fs04 boldGen">Reservation </h2>'."\n";
$code .= '</div>'."\n";

//(Your Canonlife ID  '.$_COOKIE['userid'].' )


$code .= '<div class="wrpRsv bdBtm clBd2 registerbtndiv" id="landingregister-'.$arraydata['resid'].'">'."\n";


$fully=0;
if((intval($arraydata['countconfirm'])>=intval($arraydata['seat']))&&(intval($arraydata['unseat'])==0) )
{
$fully=1;

}
if($fully==1&&$arraydata['checkhave']<1)
{
$code .='<div class="rsvThankJoin"><span class="clTxt1 fs11">Fully Reserved</span></div>';
}else
{
if($arraydata['checkhave']==0)
{


$code .='<div class="rsvBtnJoin clBgSp2" onclick="savereservedataregister('.$arraydata['productid'].','.$arraydata['resid'].')">'."\n";
$code .= '<span class="clTxtW fs11">JOIN THIS !!!</span>'."\n";
$code .= '</div>'."\n";

}
else if($arraydata['checkhave']==1)
{
$code .= '<div class="rsvThankJoin">
            <span class="clTxt1 fs11">Thank You For Joining Us</span>
        </div>'."\n";

}
else
{
 $code .='<div class="rsvThankJoin">
            <span class="clTxt1 fs11">Successful Confirmation</span>
            <span class="clTxt1 fs11">Your Canon ID : '.$_COOKIE['userid'].' </span>
        </div>'."\n";

}
}
if($fully==1&&$arraydata['checkhave']<1)
{
$code .='<div class="cpltRsv fs04 clTxt2"><span>Do not be sad. In the future we also have activities for you to enjoy.</span></div>';
}else
{
if($arraydata['checkhave']==2)
{
$code .='<div class="cpltRsv fs04 clTxt2"><span>Use your \'Canon ID\' and \'Order Number\' to contact in front of event.</span></div>';

}
else if($arraydata['checkhave']==1)
{

//$code .= '<div class="cpltRsv fs04 clTxt2">To complete reservation, you must confirmation via your email address.</div>'."\n";


$code .='<div class="cpltRsv fs04 clTxt2"><span>To complete reservation, you must confirmation via your email address.</span><span>If you do not receiving email from us, please check your Junk Email folder</span><span>or <a href="javascript:savereservedataregister('.$arraydata['productid'].','.$arraydata['resid'].')">click here to re-send email.</a></span></div>';
}
}

$code .= '</div>'."\n";



if($_COOKIE['oauth'])
{
$userdata=$this->getuserbyoauth($_COOKIE['oauth']);


$code .= '<div class="wrprRsvTtl">'."\n";
$code .= '<div class="wrpInRsvTtl clearfix">'."\n";
$code .= '<div class="wrpRsvTtl wtTtlRsv clBg5 bdFull clBd2">'."\n";
$code .= '<div class="hdRsvTtl">'."\n";
$code .= '<span class="boldGen fs05 clTxt1">Total Waiting</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="bdRsvTtl">'."\n";
$code .= '<span class="fs07 clTxt1">'.$arraydata['countwaiting'].'</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpRsvTtl cfTtlRsv clBg5 bdFull clBd2">'."\n";
$code .= '<div class="hdRsvTtl">'."\n";
$code .= '<span class="boldGen fs05 clTxt1">Total Confirmation</span>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="bdRsvTtl">'."\n";
$code .= '<span class="fs07 clTxt1">'.$arraydata['countconfirm'].'</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";

if($arraydata['checkhave']==2)
{
$code .= '<div class="wrpRsvTtl ordTtlRsv clBg5 bdFull clBd2">'."\n";

$code .= '<div class="hdRsvTtl">'."\n";
$code .= '<span class="boldGen fs05 clTxt1">Reservation Number</span>'."\n";
$code .= '</div>'."\n";

$code .= '<div class="bdRsvTtl">'."\n";
$code .= '<span class="fs07 clTxt1">'.$arraydata['resvid'].'</span>'."\n";
$code .= '</div>'."\n";

$code .= '</div>'."\n";
}

$code .= '</div>'."\n";
$code .= '</div>';


if($userdata['userid']&&$arraydata['checkmy']||$userdata['roleid']==3||$arraydata['showlist']=='1' )
{



$str1="";
$krow1=0;
$str2="";
$krow2=0;
if(count($arraydata['userlistwaiting']))
{



foreach($arraydata['userlistwaiting'] as $valueuserlist)
{

if(($arraydata['checkmy']||$userdata['roleid']==3)||($arraydata['showlist']=='1' ))
{

$code1= '<li class="clearfix" id="liuser-'.$valueuserlist['resvid'].'">'."\n";
$code1 .= '<div class="rgtName">'."\n";

$check='';
if($valueuserlist['status']==2)
{
$check=' checked="checked" ';
}
if($arraydata['checkmy']||$userdata['roleid']==3)
{
$code1 .= '<input id="checkuser-'.$valueuserlist['resvid'].'" type="checkbox" '.$check.' onclick="checkuserconfirmregister('.$valueuserlist['resvid'].','.$arraydata['productid'].')">'."\n";
}


$code1 .= '<a href="'.baseinfo.'/'.$valueuserlist['username'].'" target="_blank"><img width="24" height="24" alt="img" src="'.$valueuserlist['userssimg']['newpath'].'" class="genImgUser">'."\n";
$code1 .= '<span class="cutTxt">'.$valueuserlist['displayname'].'</span></a>'."\n";
$code1 .= '</div>'."\n";
if($arraydata['checkmy']||$userdata['roleid']==3)
{
$code1 .= '<span class="rgtInfo rgsDelRsv" onclick="deleteuserconfirmregister('.$valueuserlist['resvid'].','.$arraydata['productid'].')" >'."\n";
$code1 .= '<em class="ico icoDelRsv"></em>'."\n";
$code1 .= '</span>'."\n";
$code1 .= '<span class="rgtInfo rgtInfoRsv" onclick="openaddreservationregister(\''.$valueuserlist['displayname'].'\',\''.$valueuserlist['email'].'\',\''.$valueuserlist['phone'].'\')">'."\n";
$code1 .= '<em class="ico icoInfoRsv"></em>'."\n";
$code1 .= '</span>'."\n";
}
$code1 .= '</li>'."\n";

}else
{
$code1='';

}





if($valueuserlist['status']==1)
{
$str1.=$code1;
$krow1++;

}else
{
$str2.=$code1;
$krow2++;

}





}
}


if(count($arraydata['userlistconfirm']))
{



foreach($arraydata['userlistconfirm'] as $valueuserlist)
{

if(($arraydata['checkmy']||$userdata['roleid']==3)||$arraydata['showlist']=='1' )
{

$code1= '<li class="clearfix" id="liuser-'.$valueuserlist['resvid'].'">'."\n";
$code1 .= '<div class="rgtName">'."\n";

$check='';
if($valueuserlist['status']==2)
{
$check=' checked="checked" ';
}
if($arraydata['checkmy']||$userdata['roleid']==3)
{
$code1 .= '<input id="checkuser-'.$valueuserlist['resvid'].'" type="checkbox" '.$check.' onclick="checkuserconfirmregister('.$valueuserlist['resvid'].','.$arraydata['productid'].')">'."\n";
}


$code1 .= '<a href="'.baseinfo.'/'.$valueuserlist['username'].'" target="_blank"><img width="24" height="24" alt="img" src="'.$valueuserlist['userssimg']['newpath'].'" class="genImgUser">'."\n";
$code1 .= '<span class="cutTxt">'.$valueuserlist['displayname'].'</span></a>'."\n";
$code1 .= '</div>'."\n";
if($arraydata['checkmy']||$userdata['roleid']==3)
{
$code1 .= '<span class="rgtInfo rgsDelRsv" onclick="deleteuserconfirmregister('.$valueuserlist['resvid'].','.$arraydata['productid'].')" >'."\n";
$code1 .= '<em class="ico icoDelRsv"></em>'."\n";
$code1 .= '</span>'."\n";
$code1 .= '<span class="rgtInfo rgtInfoRsv" onclick="openaddreservationregister(\''.$valueuserlist['displayname'].'\',\''.$valueuserlist['email'].'\',\''.$valueuserlist['phone'].'\')">'."\n";
$code1 .= '<em class="ico icoInfoRsv"></em>'."\n";
$code1 .= '</span>'."\n";
}
$code1 .= '</li>'."\n";

}else
{
$code1='';

}





if($valueuserlist['status']==1)
{
$str1.=$code1;
$krow1++;

}else
{
$str2.=$code1;
$krow2++;

}





}
}





$code .= '<div class="wrprRgtCfm clearfix">'."\n";
$code .= '<div class="wrpWaitRgt clBd2 bdR">'."\n";
$code .= '<div class="wrpHdWaitRgt clearfix">'."\n";
$code .= '<h2 class="boldGen fs04 clTxt2">Waiting Status (<span class="countwaitinglist">'.$arraydata['countwaiting'].'</span>/'.$arraydata['reserve'].')</h2>'."\n";
if($arraydata['checkmy']||$userdata['roleid']==3)
{
$code .= '<input type="submit" class="btnEPRsv clBgBt1" onclick="exportuserreservationlistregister('.$arraydata['productid'].',1)" value="">'."\n";
$code .= '<input type="submit" class="btnMail clBgBt1" onclick="emailuserreservationlistregister('.$arraydata['productid'].',1)" value="">'."\n";
}

$code .= '</div>'."\n";
$code .='<div class="srchRgt">
                <div class="wrpSrchBox">
                    <input type="text" class="srchBox clBg4 fs01 clTxt3 searchwaiting" placeholder="Search">
                    <div class="btnIco srchGen" onclick="searchreservationdata('.$arraydata['productid'].',1)">
                        <span class="ico icoSrchGen"></span>
                    </div>
                </div>
            </div>';
$code .= '<ul class="lstWait">'."\n";


$code.=$str1;


$code .= '</ul>'."\n";

$code .= '<div class="pagewaiting"></div>'."\n";

$code .= '</div>'."\n";

$code .= '<div class="wrpCfmRgt">'."\n";
$code .= '<div class="wrpHdWaitRgt clearfix">'."\n";
$code .= '<h2 class="boldGen fs04 clTxt2">Confirmation Status (<span class="countconfirmlist">'.$arraydata['countconfirm'].'</span>/'.$arraydata['seat'].')</h2>'."\n";
if($arraydata['checkmy']||$userdata['roleid']==3)
{
$code .= '<input type="submit" class="btnEPRsv clBgBt1" onclick="exportuserreservationlistregister('.$arraydata['productid'].',2)" value="">'."\n";
$code .= '<input type="submit" class="btnMail clBgBt1" onclick="emailuserreservationlistregister('.$arraydata['productid'].',2)" value="">'."\n";
}

$code .= '</div>'."\n";


$code .='<div class="srchRgt">
                <div class="wrpSrchBox">
                    <input type="text" class="srchBox clBg4 fs01 clTxt3 searchconfirm" placeholder="Search">
                    <div class="btnIco srchGen" onclick="searchreservationdata('.$arraydata['productid'].',2)">
                        <span class="ico icoSrchGen"></span>
                    </div>
                </div>
            </div>';

$code .= '<ul class="lstCfm">'."\n";

$code.=$str2;



$code .= '</ul>'."\n";

$code .= '<div class="pagecomfirm"></div>'."\n";
$code .= '</div>'."\n";
$code .= '</div>'."\n";




}


}




$code .= '</div><div class="ldIt wrpFrmLd wrpRgtFrmPlgLd clBg4" id="registerform-'.$arraydata['resid'].'" style="display:none"></div>';


$data['str']=$code;
$data['target']='secondtarget';
if($arraydata['checkmy']||$userdata['roleid']==3||($arraydata['showlist']=='1' ))
{
$data['script']='getpageuserlist("#main-middle .pagewaiting",'.$arraydata['countwaiting'].',10,'.$arraydata['productid'].',1);';
$data['script'].='getpageuserlist("#main-middle .pagecomfirm",'.$arraydata['countconfirm'].',10,'.$arraydata['productid'].',2);';
$checkmypost='0';
if($arraydata['checkmy'])
{
$checkmypost=$arraydata['checkmy'];
}

$data['script'].='checkmypost='.$checkmypost.';';
$data['script'].='showlist='.$arraydata['showlist'].';';


}
//$data['script']

  return $data; 


  
  
  }
  function exportuser($productid,$status=0)
  {
  
   if($_COOKIE['oauth'])
   {
   $userdata=$this->getuserbyoauth($_COOKIE['oauth']);
   $booleancheck=$this->checkmyproductbyuserid($productid,$userdata['userid']);
   
   
   if($booleancheck||$userdata['roleid']==3)
   {    
   header("Content-Type: application/vnd.ms-excel");
          header('Content-Disposition: attachment; filename="tb_data.xls"');
        
        $sql="SELECT
            tb_plugins_reservationregister_value.`status`,
            tb_plugins_reservationregister_value.resvid,
            tb_plugins_reservationregister_value.userid,tb_user.imgmid,tb_user.simgmid,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,IF (tb_user.email = '', tb_user.emailfacebook,tb_user.email) as email,tb_user.phone,tb_user.username,tb_user.firstname,tb_user.lastname,tb_user.userid
            FROM
            tb_plugins_reservationregister_value
            inner join tb_user ON tb_user.userid=tb_plugins_reservationregister_value.userid 
             where tb_plugins_reservationregister_value.productid=".$productid.' and tb_plugins_reservationregister_value.delete=0';
  $arrayuser=$this->db->db_set_recordset($sql);
   
   ?>
   
   <html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:excel"

xmlns="http://www.w3.org/TR/REC-html40">


<HTML>

<HEAD>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</HEAD><BODY>

<TABLE  x:str BORDER="1">

 <? if($status==1||$status==0){?>
  <tr align="center">
    <td colspan="4">Wait User</td>
  </tr>

<tr align="center">
    <td>No</td>
    <td>Userid</td>
    <td>Name</td>
    <td>Displayname</td>
    <td>Username</td>
    <td>Email</td>
    <td>Tel</td> 
  </tr>
    
  
 <?
 if(count($arrayuser))
{
$k=1;
foreach($arrayuser as $valueuser)
{
if($valueuser['status']==1)
{
?>
<tr align="center">
    <td><?=$k?></td>
    <td><?=$valueuser['userid']?></td>
    <td><?=$valueuser['firstname'].' '.$valueuser['lastname']?></td>
    <td><?=$valueuser['displayname']?></td>
    <td><?=$valueuser['username']?></td>
    <td><?=$valueuser['email']?></td> 
    <td><?=$valueuser['phone']?></td> 
  </tr>


<?
}
$k++;
}


} 
 
 }?>
 
 
 
  <? if($status==2||$status==0){?>
  <tr align="center">
    <td colspan="4">Confirm User</td>
  </tr>

    <tr align="center">
    <td>No</td>
    <td>Userid</td>
    <td>Name</td>
    <td>Displayname</td>
    <td>Username</td>
    <td>Email</td>
    <td>Tel</td> 
  </tr>
    
  
 <?
 if(count($arrayuser))
{
$k=1;
foreach($arrayuser as $valueuser)
{
if($valueuser['status']==2)
{
?>
<tr align="center">
    <td><?=$k?></td>
    <td><?=$valueuser['userid']?></td>
    <td><?=$valueuser['firstname'].' '.$valueuser['lastname']?></td>
    <td><?=$valueuser['displayname']?></td>
    <td><?=$valueuser['username']?></td>
    <td><?=$valueuser['email']?></td> 
    <td><?=$valueuser['phone']?></td> 
  </tr>


<?
}
$k++;
}


} 
 
 }?>
    
  
  </TABLE>
  
  </BODY>

  </HTML>

   <?
   
   
   
   
   exit;
   }
   
   }else
   {
   $arraydata['error'][]=5;
   
   }
  
  
  }
  
  
  function emailreseruser($productid,$status=0,$msg,$title)
  {
  $arraydata['data']=array();
   if($_COOKIE['oauth'])
   {
   $userdata=$this->getuserbyoauth($_COOKIE['oauth']);
   $booleancheck=$this->checkmyproductbyuserid($productid,$userdata['userid']);
   
   
   if($booleancheck||$userdata['roleid']==3)
   {
   
   
    $sql="SELECT
            tb_plugins_reservationregister_value.`status`,
            tb_plugins_reservationregister_value.resvid,
            tb_plugins_reservationregister_value.userid,tb_user.imgmid,tb_user.simgmid,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,IF (tb_user.email = '', tb_user.emailfacebook,tb_user.email) as email,tb_user.phone,tb_user.username
            FROM
            tb_plugins_reservationregister_value
            inner join tb_user ON tb_user.userid=tb_plugins_reservationregister_value.userid 
             where tb_plugins_reservationregister_value.productid=".$productid.' and  tb_plugins_reservationregister_value.status='.$status.'  and  tb_plugins_reservationregister_value.delete=0';
  $arrayuser=$this->db->db_set_recordset($sql);
   
   if(count($arrayuser))
   {
   
    require_once(pluginpath.'/phpmailer/class.config.php'); // uri
          // http://v19.dmconnex.com/ajax/getmedthodplugin?classset=reservation&medthodset=confirmreservation&parem%5B%5D=12&parem%5B%5D=4279&parem%5B%5D=2
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           
           foreach($arrayuser as $valueuser)
           {
           
           $mail->setTo($valueuser['email'],$valueuser['displayname']);
           }
           
           
           
           $mail->setContent($msg);
           $mail->setSubject($title);
           $mail->sendTo();
           
   }
   
   
   }   
   }else
   {
   $arraydata['error'][]=5;
   
   }
  
   return $arraydata;
  }
  
  function deleteuserreservation($resvid,$productid)
  {
  $arraydata['data']=array();
  if($_COOKIE['oauth'])
   {
   $userdata=$this->getuserbyoauth($_COOKIE['oauth']);
   $booleancheck=$this->checkmyproductbyuserid($productid,$userdata['userid']);
   
   
   if($booleancheck||$userdata['roleid']==3)
   {
    $arraysetdata['delete']=1;
    $arraysetdata['updateby']=$userdata['userid'];
    $arraysetdata['updatedate']=date("Y-m-d H:i:s");
    $this->db->db_set($arraysetdata,'tb_plugins_reservationregister_value',' resvid='.$resvid);
   
   }
   
   }else
   {
   $arraydata['error'][]=5;
   
   }
   
   return $arraydata;
  
  }
  
  
  function confirmreservation($resvid,$productid,$status)
  {
  
  $arraydata['data']=array();
  
   if($_COOKIE['oauth'])
   {
   $userdata=$this->getuserbyoauth($_COOKIE['oauth']);
   $booleancheck=$this->checkmyproductbyuserid($productid,$userdata['userid']);
   if($booleancheck||$userdata['roleid']==3)
   {
   
    
   
    $arraysetdata['status']=$status;
    $arraysetdata['updateby']=$userdata['userid'];
    $arraysetdata['updatedate']=date("Y-m-d H:i:s");
    $this->db->db_set($arraysetdata,'tb_plugins_reservationregister_value',' resvid='.$resvid);
   
   }
   
   }else
   {
   $arraydata['error'][]=5;
   
   }
   
   return $arraydata;
  
  
  }
  
  
  function savereservedata($productid)
  {
    $arraydata['data']=array();
  
   if($_COOKIE['oauth'])
   {
   $userdata=$this->getuserbyoauth($_COOKIE['oauth'],',displayname,firstname,lastname,gender,birthdate,IF (tb_user.email = \'\', tb_user.emailfacebook,tb_user.email) as email,phone,description,address,countryid,proid,disid,tumid,code,facebook,twitter,googleplus,twitter,website,fax,etc,state');
   $sql="select resvid,status from tb_plugins_reservationregister_value where productid=".$productid." and userid=".$userdata['userid'].' and tb_plugins_reservationregister_value.delete=0';
   $serialall=$this->getallserialbyuserid($userdata['userid']);
   $userdata['serial']=$serialall;
   $arrayplugin=$this->db->db_set_1recordrow($sql);
   if($userdata['phone']==""||$userdata['displayname']==""||$userdata['displayname']==""||$userdata['firstname']==""||$userdata['lastname']==""||$userdata['gender']==""||$userdata['birthdate']=="0000-00-00"||$userdata['email']==""||$userdata['description']==""||$userdata['address']==""||$userdata['countryid']=="0"||$userdata['code']==""||$userdata['facebook']==""||$userdata['twitter']==""||$userdata['googleplus']==""||$userdata['twitter']==""||$userdata['website']==""||$userdata['fax']==""||$userdata['etc']=="")
   {
   
   $arraydata['data']=$userdata;
   $arraydata['error'][]=27;
      
      

   
   

   }
   else
   {
   
   
   
      if($userdata['countryid']=="210")
   {
   
   if($userdata['proid']=="0"||$userdata['disid']=="0"||$userdata['tumid']=="0")
   {
   
   $arraydata['data']=$userdata;
   $arraydata['error'][]=27;
   
   }
   
   
   
  
   }else if($userdata['state']=="")
   {

   $arraydata['data']=$userdata;
   $arraydata['error'][]=27;
   
   
   }
   
   if(count($arraydata['error'])&&isset($arraydata['error']))
   {
   
   
   }else
   {
   
   
   if($arrayplugin['resvid'])
   {
   if($arrayplugin['status']=='1')
   {
   
   require_once(pluginpath.'/phpmailer/class.config.php'); // uri
          // http://v19.dmconnex.com/ajax/getmedthodplugin?classset=reservation&medthodset=confirmreservation&parem%5B%5D=12&parem%5B%5D=4279&parem%5B%5D=2
           $mail = new ConfigMail();
   
   $mail->setTo($userdata['email'],$userdata['displayname']);
           $mail->setContent(' Thank you to join our activities.<br>This email is used to verify that your email address that your provided is real,<br> All you have to do now is click the link below for verify your registration.<br>  <a href="'.baseinfo.'/ajax/getmedthodplugin?classset=reservationregister&medthodset=confirmreservationbyuser&parem%5B%5D='.$userdata['oauth'].'&parem%5B%5D='.$productid.'&parem%5B%5D='.$arrayplugin['resvid'].'&nojson=1" target="_blank">Please Click This Link</a> <br>Thank you.<br> '.NameDmconnex.' Team');
           $mail->setSubject("Confirm Seat  From ".NameDmconnex);
           $mail->sendTo();
   
   }else
   {
   $arraydata['error'][]=30;
   
   }
   
   
   
   
   
              
   
   }else
   {
   
   $sql="select * from tb_plugins_reservationregister where productid=".$productid;
   $arrayplugin2=$this->db->db_set_1recordrow($sql);
   
   if($arrayplugin2['premium'])
   {
   if(intval($userdata['roleid'])==2||intval($userdata['roleid'])==3)
   {
   
   
   }else
   {
   
   $arraydata['error'][]=33;
   
   return $arraydata;
   
   }
   
   }
   
   $sql="select count(resvid) as countconfirmall from tb_plugins_reservationregister_value where productid=".$productid.' and tb_plugins_reservationregister_value.delete=0 and tb_plugins_reservationregister_value.status=2';
   $arrayplugin3=$this->db->db_set_1recordrow($sql);
   
   if( (intval($arrayplugin2['seat'])<=intval($arrayplugin3['countconfirmall']))&&(intval($arrayplugin2['unseat'])==0) )
   {
   
   
   
   $arraydata['error'][]=31;
   
   
   
   
   }else
   {
   
   $sql="select count(resvid) as countconfirmall from tb_plugins_reservationregister_value where productid=".$productid.' and tb_plugins_reservationregister_value.delete=0 and tb_plugins_reservationregister_value.status=1';
   $arrayplugin4=$this->db->db_set_1recordrow($sql);
   
   if( (intval($arrayplugin2['reserve'])<=intval($arrayplugin4['countconfirmall']))&&(intval($arrayplugin2['unreser'])==0)    )
   {
   
   $arraydata['error'][]=32;
   }else
   {
   
   $arraysetdata['productid']=$productid;
   $arraysetdata['userid']=$userdata['userid'];
   $arraysetdata['status']=1;
   $arraysetdata['updatedate']=date("Y-m-d H:i:s");
   $arraysetdata['createdate']=date("Y-m-d H:i:s");
   $arraysetdata['createby']=$userdata['userid'];
   $arraysetdata['updateby']=$userdata['userid'];
   $this->db->db_set($arraysetdata,'tb_plugins_reservationregister_value');
   $resvid=$this->db->db_get_last_number();
   
   require_once(pluginpath.'/phpmailer/class.config.php'); // uri
          // http://v19.dmconnex.com/ajax/getmedthodplugin?classset=reservation&medthodset=confirmreservation&parem%5B%5D=12&parem%5B%5D=4279&parem%5B%5D=2
           $mail = new ConfigMail();
           
         //  $this->db->db_set($arraysetdata,'tb_plugins_reservationregister_value');
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $arraydata['data']=$userdata;
           $mail->setTo($userdata['email'],$userdata['displayname']);
           $mail->setContent(' Thank you to join our activities.<br>This email is used to verify that your email address that your provided is real,<br> All you have to do now is click the link below for verify your registration.<br>  <a href="'.baseinfo.'/ajax/getmedthodplugin?classset=reservationregister&medthodset=confirmreservationbyuser&parem%5B%5D='.$userdata['oauth'].'&parem%5B%5D='.$productid.'&parem%5B%5D='.$resvid.'&nojson=1" target="_blank">Please Click This Link</a> <br>Thank you.<br> '.NameDmconnex.' Team');
           $mail->setSubject("Confirm Seat  From ".NameDmconnex);
           $mail->sendTo();
   
   
   }
   
   
   }
   
   
   
   
   
   
   }
   
   }
   
   
   }
   
   }else
   {
   $arraydata['error'][]=5;
   
   }
  
  return $arraydata;
  
  
  }
  

  
  
  function confirmreservationbyuser($oauth,$productid,$resvid)
    {
  
  $arraydata['data']=array();
  
   if($oauth)
   {
   $userdata=$this->getuserbyoauth($oauth);
   //$booleancheck=$this->checkmyproductbyuserid($productid,$userdata['userid']);
   if($userdata['userid'])
   {
   
   $sql="select * from tb_plugins_reservationregister where productid=".$productid;
   $arrayplugin2=$this->db->db_set_1recordrow($sql);
    
   $sql="select count(resvid) as countconfirmall from tb_plugins_reservationregister_value where productid=".$productid.' and tb_plugins_reservationregister_value.delete=0 and tb_plugins_reservationregister_value.status=2';
   $arrayplugin3=$this->db->db_set_1recordrow($sql);
   
    if((intval($arrayplugin2['seat'])<=intval($arrayplugin3['countconfirmall'])) &&(intval($arrayplugin2['unseat'])==0)  )
   {
    $arraydata['error'][]=32;
   }else
   {
    
    $arraysetdata['status']=2;
    $arraysetdata['updateby']=$userdata['userid'];
    $arraysetdata['updatedate']=date("Y-m-d H:i:s");
    $this->db->db_set($arraysetdata,'tb_plugins_reservationregister_value',' resvid='.$resvid);
   }
     
     
     
   }
   
   }else
   {
   $arraydata['error'][]=5;
   
   }
   redirectto(baseinfo.'/post/'.$productid);
   exit;
   
   return $arraydata;
  
  
  }
  
  function getplugin($plugreid)
  {
  $sql="select * from tb_plugins_reservationregister where plugreid=".$plugreid;
  $arrayplugin=$this->db->db_set_1recordrow($sql);
  
  if($_COOKIE['oauth'])
{
$userdata=$this->getuserbyoauth($_COOKIE['oauth']);
$arrayplugin['checkmy'] =$this->checkmyproductbyuserid($arrayplugin['productid'],$userdata['userid']);  


$sql="select * from tb_plugins_reservationregister_value where tb_plugins_reservationregister_value.productid=".$arrayplugin['productid'].' and tb_plugins_reservationregister_value.userid='.$userdata['userid'].' and tb_plugins_reservationregister_value.delete=0';
$arraypluginc=$this->db->db_set_1recordrow($sql);

if($arraypluginc['resvid'])
{

$arrayplugin['checkhave']=intval($arraypluginc['status']);
$arrayplugin['resvid']=$arraypluginc['resvid'];

}else
{

$arrayplugin['checkhave']=0;
$arrayplugin['resvid']=0;
}


}else
{
$arrayplugin['checkmy']=false;

} 



  
  
  
  
  $arrayplugin['userlistwaiting']=$this->getuserlistreservation($arrayplugin['productid'],1);
  $arrayplugin['userlistconfirm']=$this->getuserlistreservation($arrayplugin['productid'],2);
  $data1=$this->countuserlistreservation($arrayplugin['productid'],1);
  $arrayplugin['countwaiting']=$data1['countdata'];
  $data2=$this->countuserlistreservation($arrayplugin['productid'],2);
  $arrayplugin['countconfirm']=$data2['countdata'];

  
  return $arrayplugin;
  
  
  }
  
  }
?>
